package com.msg.handler;

import java.lang.reflect.Method;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.msg.utils.MsgSrvUtils;
import com.pjc.config.RpcReturnCode;
import com.pjc.thrift.TInnerProto;

/**
 * 协议分发类
 * 
 * @author 王畅
 * @version 创建时间：2015-7-1 下午04:50:30
 */
public class ProtoDispatcher {
	protected static final Logger log = LoggerFactory.getLogger(ProtoDispatcher.class);
	public static int dispatchProto(TInnerProto proto) throws Exception {
		try {
			log.debug("Logic to Access <<<:" + proto.data);
			Method method = MsgSrvUtils.getInstance().getMethod(proto.getId());
			if (method == null) {
				return  RpcReturnCode.NO_TARGET_METHOD;
			}
			Object rst = method.invoke(method.getClass(), new Object[] { proto.getData() });
			if (rst == null) {
				return  RpcReturnCode.OK;
			}
			return Integer.parseInt(rst.toString());
		} catch (Exception ex) {
			log.error(ex.getMessage(), ex);
		}
		return RpcReturnCode.SYS_ERROR;
	}
}
